clear all
set more off
set scheme plotplainblind

import delimited turnout.csv, clear
drop v11-v20

gen voted_valid_onpe = 100*voted_valid / voted
gen voted_blank_onpe = 100*voted_blank / voted
gen voted_null_onpe = 100*voted_null / voted

replace turnout = turnout*100

rename turnout turnout_onpe


keep dep* turnout_onpe voted_valid_onpe voted_blank_onpe voted_null_onpe called

merge 1:1 dep using vote_enaho

replace turnout = turnout*100
replace voted_valid = voted_valid * 100
replace voted_blank = voted_blank * 100
replace voted_null = voted_null * 100

corr turnout turnout_onpe [fw=called]
local rho : di %12.2fc r(rho)
two (scatter turnout turnout_onpe [fw=called], msymbol(Oh) ytitle(% from ENAHO, size(small)) xtitle(% from ONPE, size(small)) title(Turnout, size(small)) subtitle((correlation:`rho'), size(vsmall))) (lfit turnout turnout_onpe [fw=called]), legend(off)
graph save one.gph, replace

corr voted_valid voted_valid_onpe [fw=called]
local rho : di %12.2fc r(rho)
two (scatter voted_valid voted_valid_onpe [fw=called], msymbol(Oh) ytitle(% from ENAHO, size(small)) xtitle(% from ONPE, size(small)) title(Valid votes, size(small)) subtitle((correlation:`rho'), size(vsmall))) (lfit voted_valid voted_valid_onpe [fw=called]), legend(off)
graph save two.gph, replace

corr voted_blank voted_blank_onpe [fw=called]
local rho : di %12.2fc r(rho)
two (scatter voted_blank voted_blank_onpe [fw=called], msymbol(Oh) ytitle(% from ENAHO, size(small)) xtitle(% from ONPE, size(small)) title(Blank votes, size(small)) subtitle((correlation:`rho'), size(vsmall))) (lfit voted_blank voted_blank_onpe [fw=called]), legend(off)
graph save three.gph, replace

corr voted_null voted_null_onpe [fw=called]
local rho : di %12.2fc r(rho)
two (scatter voted_null voted_null_onpe [fw=called], msymbol(Oh) ytitle(% from ENAHO, size(small)) xtitle(% from ONPE, size(small)) title(Null votes, size(small)) subtitle((correlation:`rho'), size(vsmall))) (lfit voted_null voted_null_onpe [fw=called]), legend(off)
graph save four.gph, replace

graph combine one.gph two.gph three.gph four.gph
graph export votes.png, replace

erase one.gph
erase two.gph
erase three.gph
erase four.gph
